package cn.mulanbay.business.listener;

import cn.mulanbay.common.exception.ErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 系统监听器基类
 *
 * @author fenghong
 * @create 2022-01-16 10:00
 */
public class BaseListener {

    private static final Logger logger = LoggerFactory.getLogger(BaseListener.class);

    /**
     * 记录日志
     * @param errorCode
     * @param title
     * @param msg
     */
    protected void doLog(Integer errorCode, String title, String msg) {
        try {
            if (errorCode == null) {
                errorCode = ErrorCode.SUCCESS;
            }
            logger.info("系统监听,title:{},msg:{},code:{}",title,msg,errorCode);
        } catch (Exception e) {
            logger.error("doLog 异常", e);
        }

    }

    /**
     * 是否需要处理业务，Feign 可能会导致多次监听
     * @param displayName
     * @return
     */
    protected boolean needDoBuss(String displayName){
        logger.info("Listener displayName:"+displayName);
        if(displayName.contains("WebServerApplicationContext")) {
            return true;
        }else{
            return false;
        }
    }
}
